package cn.schoolwow.quickdao.module.database.dql.condition.flow.common;

import cn.schoolwow.quickdao.module.database.dql.parent.domain.QueryContext;
import cn.schoolwow.quickdao.module.database.dql.subCondition.domain.SubQueryOption;
import cn.schoolwow.quickflow.domain.FlowContext;
import cn.schoolwow.quickflow.flow.BusinessFlow;

public class SetJoinTableIndexFlow implements BusinessFlow {
    @Override
    public void executeBusinessFlow(FlowContext flowContext) throws Exception {
        QueryContext queryContext = (QueryContext) flowContext.checkData("queryContext");

        for(SubQueryOption subQueryOption:queryContext.queryOption.subQueryOptionList){
            if(null==subQueryOption.subQueryTableOption.tableAliasName){
                subQueryOption.subQueryTableOption.tableAliasName = "t"+subQueryOption.subQueryJoinTableOption.queryOption.queryTableOption.joinTableIndex++;
            }
        }
    }

    @Override
    public String name() {
        return "设置关联表计数";
    }

}
